<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2022/3/5
 * Time: 16:09
 */

namespace app\api\controller;
use app\common\controller\Api;
use think\Request;
use think\Db;
class About extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    /**
     * 铁血简介
     */
    public function introduction()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        $info = Db::name('introduction')->find();
        if(!$info)
            $this->error('暂无数据');
        $this->success('',$info);
    }

    /**
     * 资料下载
     */
    public function data_download()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        $page = input('post.page',1);
        $limit = input('post.limit',10);

        $list = Db::name('data_download')->paginate($limit,'',['page'=>$page]);
        if(!$list)
            $this->error('暂无数据');
        $list = $list->toArray();
        foreach ($list['data'] as $k=>&$v)
        {
            $v['time'] = date('Y-m-d',$v['createtime']);
        }

        $this->success('',$list);
    }

    /**
     * 招聘信息
     */
    public function recruitment_information()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        $info = Db::name('recruitment_information')->find();
        if(!$info)
            $this->error('暂无数据');
        $this->success('',$info);
    }

    /**
     * 常见问题列表
     */
    public function common_problem_list()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        $list = Db::name('common_problem')->field('id,title,content')->select();
        if(!$list)
            $this->error('暂无数据');
        $this->success('',$list);
    }

    public function common_problem_detail()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        if(!$id = input('get.id'))
        {
            $this->error('缺少参数');
        }

        $info = Db::name('common_problem')->where('id',$id)->find();
        if(!$info)
            $this->error('暂无数据');
        $info['time'] = date('Y-m-d',$info['createtime']);
        Db::name('common_problem')->where('id',$id)->setInc('look');
        $this->success('',$info);
    }

    /**
     * 公告管理
     */
    public function notice()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');

        $list = Db::name('notice')->field("id,title,content,look,is_top,createtime,FROM_UNIXTIME(createtime,'%Y-%m-%d') as time")->where('is_show',1)->order('id','desc')->limit(10)->select();


        if(!$list)
            $this->error('暂无数据');

        $this->success('',$list);
    }

    //铁血荣誉
    public function honor()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        $limit = input('post.limit',6);
        $list = Db::name('honor')->field("id,title,image")->order('id','desc')->limit($limit)->select();

        if(!$list)
            $this->error('暂无数据');

        $this->success('',$list);
    }

    //师资团队
    public function teacher()
    {
        if (!Request::instance()->isGet())
            $this->error('请求方式不正确');
        $limit = input('post.limit',6);
        $list = Db::name('teacher')->field("id,head_avatar,name,type")->order('id','desc')->limit($limit)->select();

        if(!$list)
            $this->error('暂无数据');

        $this->success('',$list);
    }
}